//
//  CountDownGameScene.cpp
//  CanYouDoIt
//
//  Created by hoangtx on 7/9/13.
//
//

#include "CountDownGameScene.h"
#include "SceneManager.h"
#include "GameLayerManager.h"
#include "StaticVariables.h"
#include "GameLayerManager.h"
CCScene* CountDownGameScene::scene(int numberOfSeconds){
    // 'scene' is an autorelease object
    CCScene *scene = CCScene::create();
    
    // 'layer' is an autorelease object
    CountDownGameScene *layer = CountDownGameScene::create(numberOfSeconds);
    
    // add layer as a child to scene
    scene->addChild(layer);
    
    // return the scene
    return scene;
}


bool CountDownGameScene::init(){
    MyGameScene::init();
    scoreAndTimeLayer->turnToType(GAME_COUNT_DOWN);
    numberOfTap = 0;
    return true;
}

CountDownGameScene* CountDownGameScene::create(int numberOfSeconds){
    CountDownGameScene* scene = CountDownGameScene::create();
    scene->maxTimeCountDown = numberOfSeconds;
    scene->timeRemaining = scene->maxTimeCountDown;
    scene->scoreAndTimeLayer->updateTime(scene->timeRemaining);
    return scene;
}

void CountDownGameScene::didShowingFailMessage(float dt){
    MyGameScene::didShowingFailMessage(dt);
    GameLayerManager::sharedInstance()->resultLayer->getScoreToDisplayResult(numberOfTap);
}


void CountDownGameScene::reset(){
    MyGameScene::reset();
    numberOfTap = 0;
    timeRemaining = maxTimeCountDown;
    scoreAndTimeLayer->updateTime(timeRemaining);
    scoreAndTimeLayer->updateScore(numberOfTap);
    
    
}

void CountDownGameScene::onTick(float dt){
    timeRemaining--;
    scoreAndTimeLayer->updateTime(timeRemaining);
    if(timeRemaining==0){
        this->unscheduleAllSelectors();
        setTouchEnabled(false);
        
        CCTransitionFlipX* transition = CCTransitionFlipX::create(0.5f, SceneManager::sharedInstance()->resultScene, kCCTransitionOrientationLeftOver);
        CCDirector::sharedDirector()->replaceScene(transition);
        GameLayerManager::sharedInstance()->resultLayer->getScoreToDisplayResult(numberOfTap);
    }
}

